package com.ctshk.rpc.order.goods.mapper;

import com.ctshk.rpc.order.goods.base.CustomBaseMapper;
import com.ctshk.rpc.order.goods.dto.ShoppingSpecialDetailedDTO;
import com.ctshk.rpc.order.goods.entity.ShoppingSpecialCommodity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 专题商品 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-30
 */
public interface ShoppingSpecialCommodityMapper extends CustomBaseMapper<ShoppingSpecialCommodity> {

    @Select("select t.id,t.special_id,t.commodity_id,t.sort,t.gmt_create,t.create_id,t.gmt_modified,t.modified_id,t.is_deleted " +
            "from `ctshk-goods`.t_shopping_special_commodity t " +
            "where t.is_deleted = 0 and t.special_id = #{specialId}")
    List<ShoppingSpecialCommodity> findShoppingSpecialCommodityBySpecialId(@Param("specialId") Long specialId);

    /**
     * 根据商品专题id查询专题商品明细
     * @param id
     * @return
     */
    @Select({
        "SELECT ss.*,ssc.*,cc.price,cc.marking_price,cl.label_type \n" +
                "FROM `ctshk-goods`.t_shopping_special ss\n" +
                "LEFT JOIN `ctshk-goods`.t_shopping_special_commodity ssc \n" +
                "ON ss.id = ssc.special_id\n" +
                "LEFT JOIN `ctshk-goods`.t_commodity_cost cc\n" +
                "ON cc.commodity_id = ssc.commodity_id\n" +
                "LEFT JOIN `ctshk-goods`.t_commodity_label cl\n" +
                "ON ssc.commodity_id = cl.commodity_id\n" +
                "WHERE ss.id = ${specialId} \n" +
                "GROUP BY ss.id"
    })
    List<ShoppingSpecialDetailedDTO> selectListBySpecialId(@Param("specialId") Long id);

    /**
     * 根据专题id查询专题商品信息
     * @param id
     * @return
     */
    @Select({
            "SELECT * FROM `ctshk-goods`.t_shopping_special_commodity WHERE special_id = #{id}"
    })
    List<ShoppingSpecialCommodity> selectListById(@Param("id") Long id);

    /**
     * 根据id查询专题商品列表
     * @param id
     * @return
     */
    @Select({
            "SELECT  id,special_id,commodity_id,sort,create_id,modified_id,is_deleted,gmt_create,gmt_modified  FROM `ctshk-goods`.t_shopping_special_commodity     WHERE (special_id = #{id})"
    })
    List<ShoppingSpecialCommodity> selectAllList(@Param("id") Long id);
}
